<!DOCTYPE html>
<html lang="zh-cn">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>我的培训需求</title>


  <!-- Expand styles -->
  <link href="../css/app/app.css" rel="stylesheet">
  <link href="../css/app/default.css" rel="stylesheet">
  <link href="../css/mui/mui.css" rel="stylesheet">


  <!-- Custom styles for this template -->
  <!-- <link href="../css/iOS/mobile/mobile.css" rel="stylesheet"> -->
</head>

<body>

  <!-- header -->
  <div class="mobile-content5">
    <div class="widget-default margin-b-5">
      <div class="farming-tab">
        <div id="segmentedControl" class="mui-segmented-control">
          <a class="mui-control-item mui-active" href="#item1" id="0">报价进行中</a>
          <a class="mui-control-item" href="#item2" id="1">报价已结束</a>
          <a class="mui-control-item" href="#item3" id="2">需求已关闭</a>
        </div>
      </div>
    </div>
    <!-- 内容 -->
    <div id="pullrefresh" class="mui-content mui-scroll-wrapper" style="margin-top: 60px;">
      <div class="mui-scroll">
        <div id="list">

        </div>
      </div>
    </div>
  </div>



  <script type="text/javascript" src="../js/jquery.js"></script>
  <script type="text/javascript" src="../js/mui/mui.js"></script>
  <script src="../js/dsbridge.js"></script>
  <script src="../js/mui/mui.picker.min.js"></script>
  <script src="../js/layer.js"></script>
  <script src="../js/app/app-base.js"></script>
  <script src="../js/app/app-url.js"></script>
  <script src="../js/app/app-ajax.js"></script>
  <script>

    var page = 1;
    var limit = 10;
    var index = 0;
    //点赞数据index
    var praiseIndex = -1;
    //分享数据index
    var shareIndex = -1;
    var all_data = new Array();

    var confirmStatus = "0";
    $(document).ready(function () {

      mui.init({
        pullRefresh: {
          container: '#pullrefresh',
          down: {
            auto: true, // 首次进入自动加载
            callback: pulldownRefresh
          },
          up: {
            contentrefresh: '正在加载...',
            callback: pullupRefresh
          }
        }
      });

      dsBridge.register('refresh', function () {
        pulldownRefresh();
      })

      dsBridge.register('add', function () {
        localStorage.setItem("tranDemand_Id", "");
      })
    });



    /**
    * 下拉刷新具体业务实现
    */
    function pulldownRefresh() {
      page = 1;
      getData()
    }

    /**
    * 上拉加载具体业务实现
    */
    function pullupRefresh() {
      page++;
      getData();
    }

    function getData() {
      var data = {
        userId: getUserId(),
        page: page,
        limit: limit,
        sourceType: 'my_demand',
        confirmStatus: confirmStatus,
        limit: 5
      }
      getServerData(url_myNeedsQueryList, data);
    }


    function getServerDataSuccess(url, data) {
      switch (url) {
        //详情
        case url_myNeedsQueryList:
          layer.closeAll();
          var list = data.data;
          var html_data = "";
          if (page == 1) {
            index = 0;
            all_data.length = 0;
          }
          if (list.length > 0) {
            for (var i = 0; i < list.length; i++) {
              all_data.push(list[i]);
              var s = list[i]
              if (confirmStatus == "0") {
                html_data += '<div class=" widget-body widget-default margin-b-1 ">' +
                  '<div class="display-flex align-items-center margin-b-10">' +
                  '<span class="px-content font-15 tuli-bg-b elli1">' + s.tranTypeName + '</span>' +
                  '<p class="black1 font-16 font-weight no-margin elli1 padding-r-10">' + s.title +
                  '</p>' +
                  '</div>' +
                  '<div class="display-flex align-items-center justify-content-between padding-t-5">' +
                  '<p class="font-12 gray no-margin">' + '主办方：' + s.tranSponsors + '</p>' +
                  '<span class="font-16 font-weight red">' + '￥' + s.budgetShow + '</span>' +
                  '</div>' +
                  '<div class="display-flex align-items-center justify-content-between">' +
                  '<p class="font-12 gray no-margin">' + '培训地址：' + s.tranAddress + '</p>' +
                  '<span class="font-12 gray">' + s.quoteNum + '人已报价' + '</span>'
                  + '</div>' +
                  '</div>' +
                  '<div class="text-right padding-10-15 widget-default goDetail" dId="' + index + '">'
                  + '<span class="tuli-content2 font-13 tuli-bg-b selectAgency">' + '选择合作机构' + '</span>'
                  + '<span class="tuli-content2 font-13 closeNeed" cId="' + s.id + '">' + '关闭需求' + '</span>'
                  + '<span class="tuli-content2 font-13 seeDetail">' + '查看详情' + '</span>'
                  + '</div>'
              }
              if (confirmStatus == "1") {
                html_data += '<div class=" widget-body widget-default margin-b-1 " id="' + index + '">' +
                  '<div class="display-flex align-items-center margin-b-10">' +
                  '<span class="px-content font-15 tuli-bg-b elli1">' + s.tranTypeName + '</span>' +
                  '<p class="black1 font-16 font-weight no-margin elli1 padding-r-10">' + s.title +
                  '</p>' +
                  '</div>' +
                  '<div class="display-flex align-items-center justify-content-between padding-t-5">' +
                  '<p class="font-12 gray no-margin">' + '主办方：' + s.tranSponsors + '</p>' +
                  '<span class="font-16 font-weight red">' + '￥' + s.budgetShow + '</span>' +
                  '</div>' +
                  '<div class="display-flex align-items-center justify-content-between">' +
                  '<p class="font-12 gray no-margin">' + '培训地址：' + s.tranAddress + '</p>' +
                  '<span class="font-12 gray">' + s.quoteNum + '人已报价' + '</span>'
                  + '</div>' +
                  '</div>' +
                  '<div class="text-right padding-10-15 widget-default goDetail" dId="' + index + '">'
                  + '<span class="tuli-content2 font-13 tuli-bg-b selectAgency">' + '选择合作机构' + '</span>'
                  + '<span class="tuli-content2 font-13 seeDetail">' + '查看详情' + '</span>'
                  + '</div>'
              }
              if (confirmStatus == "2") {
                var imgs = ''
                if (s.closeStatus == '2') {
                  imgs = '<img class="pxsuccess-img" src="../img/px-success.png" alt="">'
                } else if (s.closeStatus == '3') {
                  imgs = '<img class="pxsuccess-img" src="../img/px-contradict.png" alt="">'
                } else {
                  imgs = '<img class="pxsuccess-img" src="../img/px-fail.png" alt="">'
                }
                var btn = ""
                if (s.closeStatus == '3') {
                  btn = '<span class="tuli-content2 font-13 bhWhy" BId="' + s.id + '"  bhtxt="' + s.auditOpinion + '">' + '驳回原因' + '</span>'
                }
                html_data += '<div class="margin-b-10">' +
                  '<div class="trade-list widget-body widget-default margin-b-1">'
                  + '<div class="display-flex align-items-center margin-b-10">' +
                  '<span class="px-content font-15 tuli-bg-b elli1">' + s.tranTypeName + '</span>'
                  + '<p class="black1 font-16 font-weight no-margin elli1 padding-r-10">' + s.title +
                  ' </p>'
                  + '</div>'
                  + imgs
                  + '<div class="display-flex align-items-center justify-content-between padding-t-5">'
                  + '<p class="font-12 gray no-margin">主办方:' + s.tranSponsors + '</p>'
                  + '<span class="font-16 font-weight red">' + '￥' + s.budgetShow + '</span>'
                  + '</div>'
                  + '<div class="display-flex align-items-center justify-content-between">'
                  + '<p class="font-12 gray no-margin">' + '培训地址：' + s.tranAddress + '</p>'
                  + '<span class="font-12 gray">' + s.quoteNum + '人已报价' + '</span>'
                  + '</div>'
                  + '</div>'
                  + '<div class="text-right padding-10-15 widget-default goDetail" dId="' + index + '">';

                if (s.closeStatus == '2') {
                  html_data += '<span class="tuli-content2 font-13 tuli-bg-b seeAgency">' + '查看合作机构' + '</span>';
                }
                if (s.quoteNum == 0 && s.closeStatus != 2 && s.closeStatus != 3) {
                  html_data += '<span class="tuli-content2 font-13 goEdit"  dId="' + s.id + '">' + '修改' + '</span>';

                }
                html_data += '<span class="tuli-content2 font-13 seeDetail">' + '查看详情' + '</span>'
                  + '<span class="tuli-content2 font-13 delNeed" dId="' + s.id + '">' + '删除' + '</span>'
                  + btn
                  + '</div>'
                  + '</div>'
              }

              index++;
            }
            ;
          }


          if (page == 1) {
            mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
            if (list.length > 0) {
              mui('#pullrefresh').pullRefresh().refresh(true);
            }
            $("#list").html(html_data);
          } else {
            $("#list").append(html_data);
            mui('#pullrefresh').pullRefresh().endPullupToRefresh(list.length != limit);
          }

          break;
        case url_commonoper_operAction + '?type=praise':
          $(".widget-body[id='" + praiseIndex + "']").find(".praiseImg").attr("src", "../img/applaud.png");
          var $praiseNum = $(".widget-body[id='" + praiseIndex + "']").find(".praiseNum");
          var praiseNum = Number($praiseNum.text()) + 1;
          $praiseNum.text(praiseNum);
          break;
        case url_oper_action_cancel + '?type=praise':

          //取消点赞
          $(".widget-body[id='" + praiseIndex + "']").find(".praiseImg").attr("src", "../img/zai.png");
          var $praiseNum = $(".widget-body[id='" + praiseIndex + "']").find(".praiseNum");
          var praiseNum = Number($praiseNum.text()) - 1;
          if (praiseNum < 0) {
            praiseNum = 0;
          }
          $praiseNum.text(praiseNum);
          break;
        case url_deleteDemand:
          showToast('删除成功')
          pulldownRefresh();
          break;
        case url_closeDemand:
          showToast('关闭成功')
          pulldownRefresh();
          break;

      }
    }


    function getServerDataFailed(url, data) {
      mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
      mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
    }

    mui("#list").on('tap', '.goEdit', function () {
      var dId = $(this).attr("dId");
      localStorage.setItem("tranDemand_Id", dId);
      dsBridge.call("goEdit", "");
    });


    //详情
    mui("#list").on('tap', '.seeDetail', function () {
      var detailIndex = $(this).parents(".goDetail").attr("dId");
      localStorage.setItem("tranDemand_Id", all_data[detailIndex].id);
      localStorage.setItem("tranDemandDetail_sourceType", 'my-training');
      dsBridge.call("goDetail", "");
    });


    mui(".trade-list").on('tap', '.person-info', function () {
      dsBridge.call("goPersonInfo", $(this).attr("id"));
    });

    // //点赞/取消点赞
    // mui(".trade-list").on('tap', '.praiseOper', function () {
    //   praiseIndex = $(this).parents(".widget-body").attr("id");
    //   if ($(this).parents(".widget-body").find("img.praiseImg").attr("src") == '../img/zai.png') {
    //     //点赞
    //     var data = {
    //       userId: getUserId(),
    //       itemType: 19,
    //       itemId: all_data[praiseIndex].id,
    //       actionType: 2,
    //       channel: 2
    //     }
    //     getServerData(url_commonoper_operAction + '?type=praise', data);
    //   } else {

    //     //取消点赞
    //     var data = {
    //       userId: getUserId(),
    //       itemId: all_data[praiseIndex].id,
    //       actionType: 2
    //     }
    //     getServerData(url_oper_action_cancel + '?type=praise', data);
    //   }

    // });

    //分享
    // mui(".trade-list").on('tap', '.shareOper', function () {
    //   shareIndex = $(this).parents(".widget-body").attr("id");
    //   dsBridge.call("share", all_data[shareIndex]);
    // });

    mui(".mui-segmented-control").on('tap', 'a', function () {
      loading();
      confirmStatus = this.id;
      getData();
    });

    mui("#list").on('tap', '.closeNeed', function () {
      var cId = $(this).attr("cId");
      layer.open({
        content: '需求关闭后培训机构将不能参与本需求的报价，已投标的培训机构将被系统默认淘汰！'
        , btn: ['确定', '取消']
        , yes: function (index) {
          var data = {
            id: cId
          }
          getServerData(url_closeDemand, data);

          layer.close(index);
        }
      });
    });

    mui("#list").on('tap', '.delNeed', function () {
      var dId = $(this).attr("dId");
      layer.open({
        content: '确定删除需求吗？'
        , btn: ['确定', '取消']
        , yes: function (index) {
          var data = {
            id: dId
          }
          getServerData(url_deleteDemand, data);
          layer.close(index);
        }
      });
    });

    mui("#list").on('tap', '.bhWhy', function () {
      var BId = $(this).attr("BId");
      var bhtxt = $(this).attr("bhtxt");
      layer.open({
        content: bhtxt
        , btn: ['确定']
        , yes: function (index) {
          layer.close(index);
        }
      });
    });

    //选择合作机构
    mui("#list").on('tap', '.selectAgency', function () {
      var selectIndex = $(this).parents(".goDetail").attr("dId");
      localStorage.setItem("baojia-id", all_data[selectIndex].id);
      dsBridge.call("selectAgency", "");
    });

    //查看合作机构
    mui("#list").on('tap', '.seeAgency', function () {
      var seeIndex = $(this).parents(".goDetail").attr("dId");
      localStorage.setItem("baojia-result-id", all_data[seeIndex].id);
      log(all_data[seeIndex].id);
      dsBridge.call("seeAgency", "");
    });

  </script>

</body>

</html>